﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;

using Fuse8.DomainFramework.Common;
using Fuse8.DomainFramework.DataAccess.SqlDatabase;

using Fuse8.ContentManagementFramework.Domain;

namespace Fuse8.ContentManagementFramework.DataAccess.SqlAccess.Mappers
{
    internal class CmsPageControlDataMapper : BaseSqlEntityDataMapper<CmsPageControl, int>
    {
        private static BaseSqlEntityDataMapper<CmsPageControl, int> _based = new BaseSqlEntityDataMapper<CmsPageControl, int>(new string[] { "Page", "TemplateRegion" });

        private static Dictionary<string, Func<object, IList<SqlParameter>>> _mappersTo = new Dictionary<string, Func<object, IList<SqlParameter>>>();

        static CmsPageControlDataMapper()
        {   
            _mappersTo.Add("cms_sp_PageAddPageControl",
                (p) =>
                {
                    return _based.MapTo("cms_sp_PageAddPageControl", p, true);
                });
        }

        public CmsPageControlDataMapper()
            : base(new string[] { "Page", "TemplateRegion", "Module", "EntityMetaInformation", "PageControlContent", "PageControlTypeDescription", "CommonPageControlType" })
        { }

        public override IList<SqlParameter> MapTo(string sp, object parameter, bool isForCreate)
        {
            Guard.ArgumentNotEmpty(sp, "sp");

            return _mappersTo.ContainsKey(sp) ?
                _mappersTo[sp](parameter) :
                base.MapTo(sp, parameter, isForCreate);
        }
    }
}
